home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
BASICS.ZIP
/
CLASSLIB
/
CFRAME.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-25
|
29KB
|
1,250 lines
/*
* CFRAME.CPP
* Sample Code Class Libraries
*
* Generic CFrame class that manages either SDI or MDI clients as
* well as typical File, Edit, Window, and Help commands.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include <windows.h>
#include <memory.h>
extern "C"
{
#include <commdlg.h>
}
#include <win1632.h>
#include <debug.h>
#include "classlib.h"
/*
* CFrame::CFrame
* CFrame::~CFrame
*
* Constructor Parameters:
* hInst HINSTANCE from WinMain
* hInstPrev HINSTANCE from WinMain
* pszCmdLine LPSTR from WinMain
* nCmdShow int from WinMain
*/
CFrame::CFrame(HINSTANCE hInst, HINSTANCE hInstPrev
, LPSTR pszCmdLine, int nCmdShow)
: CWindow(hInst)
{
m_hInstPrev =hInstPrev;
m_pszCmdLine=pszCmdLine;
m_nCmdShow =nCmdShow;
m_phMenu=NULL;
m_hBmp=NULL;
m_pST=NULL;
m_pGB=NULL;
m_pSS=NULL;
m_pCL=NULL;
m_pAdv=NULL;
return;
}
CFrame::~CFrame(void)
{
m_fClosing=TRUE;
if (NULL!=m_pAdv)
delete m_pAdv;
//Accelerators freed automatically.
//Free the GizmoBar bitmaps
if (NULL!=m_hBmp)
DeleteObject(m_hBmp);
if (NULL!=m_pCL)
delete m_pCL;
if (NULL!=m_pSS)
delete m_pSS;
if (NULL!=m_pGB)
delete m_pGB;
//Free the menu handle array
if (NULL!=m_phMenu)
delete []((UINT FAR *)m_phMenu);
//Free the stringtable.
if (NULL!=m_pST)
delete m_pST;
m_fClosing=FALSE;
return;
}
/*
* CFrame::FInit
*
* Purpose:
* Initializer for a CFrame object containing anything prone to
* failure, typically creating the main window and loading resources.
*
* Parameters:
* pFI LPFRAMEINIT containing initialization parameters.
*
* Return Value:
* BOOL TRUE if initialization succeeded, FALSE otherwise.
* If FALSE is returned, the caller must guarantee that
* the destructor is called promptly to insure cleanup.
*/
BOOL CFrame::FInit(LPFRAMEINIT pFI)
{
RECT rc;
HMENU hMenu;
UINT uTemp;
TOOLDISPLAYDATA tdd;
m_fInit=TRUE;
//1. Create our stringtable
m_pST=new CStringTable(m_hInst);
if (!m_pST->FInit(pFI->idsMin, pFI->idsMax))
return FALSE;
/*
* 2. Register the classes we need for this application.
* We have our main (frame) window, document windows (for
* either MDI or SDI, and Polyline windows which are the
* editing controls. This separate virtual function allows
* applications to add additional classes.
*/
if (NULL==m_hInstPrev)
{
if (!FRegisterAllClasses())
return FALSE;
}
/*
* 3. Create the main window, the gizmobar, the StatStrip,
* and a client that owns documents.
*/
m_pCL=NULL;
m_hWnd=CreateWindow(SZCLASSFRAME, PSZ(IDS_CAPTION)
, WS_MINIMIZEBOX | WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
, CW_USEDEFAULT, CW_USEDEFAULT
, 440, 460, NULL, NULL, m_hInst, (LPVOID)this);
if (NULL==m_hWnd)
return FALSE;
GetClientRect(m_hWnd, &rc);
UIToolConfigureForDisplay(&tdd);
m_dxB=tdd.cxButton;
m_dyB=tdd.cyButton;
m_cyBar=tdd.cyBar;
m_pGB=new CGizmoBar(m_hInst);
if (!m_pGB->FInit(m_hWnd, ID_GIZMOBAR, m_cyBar))
return FALSE;
m_pSS=new CStatStrip(m_hInst);
if (!m_pSS->FInit(m_hWnd, ID_STATSTRIP, CYSTATSTRIP))
return FALSE;
//Initialize the StatStrip for automated WM_MENUSELECT processing.
if (!m_pSS->MessageMap(m_hWnd, m_hInst, IDR_STATMESSAGEMAP
, pFI->idsStatMin, pFI->idsStatMax, CCHMESSAGEMAX
, pFI->idStatMenuMin, pFI->idStatMenuMax, ID_MESSAGEREADY
, ID_MESSAGEEMPTY, ID_MENUSYS))
return FALSE;
rc.top+=m_cyBar;
m_pCL=CreateCClient();
/*
* 4. Allocate space for the menu handle array and store the popup
* handles. Get the menu handle of the Window menu specifically
* for later processing.
*/
hMenu=GetMenu(m_hWnd);
m_phMenu=new HMENU[pFI->cMenus];
for (uTemp=0; uTemp < pFI->cMenus; uTemp++)
m_phMenu[uTemp]=GetSubMenu(hMenu, uTemp);
//Save this for UpdateMenus
m_hMenuWindow=GetSubMenu(hMenu, pFI->iPosWindowMenu);
if (!m_pCL->FInit(m_hMenuWindow, &rc, this))
return FALSE;
/*
* 5. Initialize fancy things like the gizmobar. If a derived class
* wants more gizmo images, they can copy the first two in the
* standard image set and this code will still load it. This
* code just won't reference it.
*/
m_hBmp=LoadBitmap(m_hInst, MAKEINTRESOURCE(tdd.uIDImages));
if (NULL==m_hBmp)
return FALSE;
//Create all the gizmos on the gizmobar
CreateGizmos();
UpdateGizmos();
m_hAccel=LoadAccelerators(m_hInst, MAKEINTRESOURCE(IDR_ACCELERATORS));
if (NULL==m_hAccel)
return FALSE;
/*
* 6. Before we possibly create any new documents, create an
* AdviseSink for document notifications.
*/
m_pAdv=new CDocumentAdviseSink((LPVOID)this);
/*
* 7. In the default implementation FPreShowInit does not do
* anything, but is called here to allow derivations to
* hook the function and modify m_nCmdShow before we
* call ShowWindow. This is one such place where OLE affects
* a derivation, because servers will change m_nCmdShow to
* SW_HIDE if started with -Embedding.
*/
if (!FPreShowInit())
return FALSE;
/*
* 8. Handle window visibility appropriately after giving
* FPreShowInit a chance to modify it.
*/
ShowWindow(m_hWnd, m_nCmdShow);
UpdateWindow(m_hWnd);
/*
* 9. Parse the command line and take appropriate action. Again,
* this virtual function is here for applications to override.
*/
ParseCommandLine();
m_fInit=FALSE;
return TRUE;
}
/*
* CFrame::CreateCClient
*
* Purpose:
* Creates a CClient object for use in this frame. This function is
* overrided by derived classes to create a different type of CClient.
*
* Parameters:
* None
*
* Return Value:
* LPCClient Pointer to the new CClient object.
*/
LPCClient CFrame::CreateCClient()
{
return new CClient(m_hInst);
}
/*
* CFrame::FRegisterAllClasses
*
* Purpose:
* Registers all classes used in this application.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if registration succeeded, FALSE otherwise.
*/
BOOL CFrame::FRegisterAllClasses(void)
{
WNDCLASS wc;
//Field that are the same for all windows.
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hInstance = m_hInst;
wc.cbClsExtra = 0;
//Register the Frame window
wc.lpfnWndProc = FrameWndProc;
wc.cbWndExtra = CBFRAMEWNDEXTRA;
wc.hIcon = LoadIcon(m_hInst, "Icon");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = SZCLASSFRAME;
if (!RegisterClass(&wc))
return FALSE;
#ifndef MDI
wc.lpfnWndProc = SDIClientWndProc;
wc.cbWndExtra = CBCLIENTWNDEXTRA;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = SZCLASSSDICLIENT;
if (!Regi